package org.example
import org.apache.spark.sql.SparkSession
import java.util.Properties
object MySQL {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession
      .builder()
      .master("local[*]")
      .appName("sparkBase")
      .getOrCreate()
    val sc = spark.sparkContext
    // 连接并读取MySQL数据
    val pro: Properties = new Properties()
    pro.setProperty("user","root")
    pro.setProperty("password","123456")
    pro.setProperty("driver","com.mysql.jdbc.Driver") //8.0以上加.cj
    val mysqlData = spark.read.jdbc("jdbc:mysql://localhost:3306/mysql?" +
      "verifyServerCertificate=false&useSSL=false","user",pro)
    mysqlData.show()

    val sparkScore = spark.read
      .option("encoding", "GBK")
      .option("header", "true")
      .csv("src/main/resources/23yun1.csv")

    sparkScore.show(5)

    sc.stop()
  }
}